package com.wmx.es.entity;

import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.util.Date;

/**
 * 单位信息-实体对象
 * <p>
 * 1、@Document 注解用于标识实体（文档）存储的位置，即指定索引、类型，相当于存在在哪个数据库的哪个表中
 * indexName：索引，必须指定，不存在时，会自动创建
 * type：类型，不存在时，会自动创建
 * shards：分片，默认 5
 * replicas：副本，默认 1
 *
 * @author wangmaoxiong
 * @version 1.0
 * @date 2020/5/31 17:15
 */
@Document(indexName = "agency", type = "agency_type", shards = 5, replicas = 1)
public class Agency {

    /**
     * 1、@Id：标记主键列
     * 2、@Field ：标记普通列信息
     * 3、index：是否设置分词/是否索引，默认 true
     * 4、store：是否存储（默认 false）。为 false 并不代表在 es 中数据不存在。
     * 5、analyzer：存储时使用的分词器
     * 6、searchAnalyze：搜索时使用的分词器
     * 7、type: 数据类型
     */
    @Id
    @Field(store = true, index = false, type = FieldType.Text)
    private String agencyId;
    @Field(index = true, store = true, analyzer = "ik_max_word", searchAnalyzer = "ik_smart", type = FieldType.Text)
    private String agencyCode;
    @Field(index = true, store = true, analyzer = "ik_max_word", searchAnalyzer = "ik_smart", type = FieldType.Text)
    private String agencyName;
    // 日期默认存储为 Long 类型，可以通过 format 属性指定格式
    @Field(index = true, store = true, type = FieldType.Date, format = DateFormat.none)
    private Date establishmentTime;
    @Field(index = true, store = true, analyzer = "ik_max_word", searchAnalyzer = "ik_smart", type = FieldType.Text)
    private String address;
    @Field(store = false, type = FieldType.Long)
    private Long employeesCount;

    public String getAgencyId() {
        return agencyId;
    }

    public void setAgencyId(String agencyId) {
        this.agencyId = agencyId;
    }

    public String getAgencyCode() {
        return agencyCode;
    }

    public void setAgencyCode(String agencyCode) {
        this.agencyCode = agencyCode;
    }

    public String getAgencyName() {
        return agencyName;
    }

    public void setAgencyName(String agencyName) {
        this.agencyName = agencyName;
    }

    public Date getEstablishmentTime() {
        return establishmentTime;
    }

    public void setEstablishmentTime(Date establishmentTime) {
        this.establishmentTime = establishmentTime;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public Long getEmployeesCount() {
        return employeesCount;
    }

    public void setEmployeesCount(Long employeesCount) {
        this.employeesCount = employeesCount;
    }


    @Override
    public String toString() {
        return "Agency{" +
                "agencyId='" + agencyId + '\'' +
                ", agencyCode='" + agencyCode + '\'' +
                ", agencyName='" + agencyName + '\'' +
                ", establishmentTime=" + establishmentTime +
                ", address='" + address + '\'' +
                ", employeesCount=" + employeesCount +
                '}';
    }
}
